﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WXWeb.Admin
{
    public partial class UserList : BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetQeuryString("para") == "GetUserList")
            {
                BindData();
            }
            else if (GetQeuryString("para") == "deleteUser")
            {
                try
                {
                    Response.Clear();
                    string id = GetQeuryString("id");
                    access.DelteUserByID(id);
                    Response.Write("ok");
                }
                catch (Exception ex)
                {
                    Response.Write("Error" + ex.Message);
                }
                finally
                {
                    Response.End();
                }

            }

        }

        private void BindData()
        {
            Response.Clear();
            //string s = "{\"total\":\"239\",\"rows\":[  {\"code\":\"001\",\"name\":\"Name 1\",\"addr\":\"Address 11\",\"addr\":\"col4 data\"}   ]}  ";
            int PageNumber = Convert.ToInt32(Request.Params["page"] == null ? "1" : Request.Params["page"]) - 1;
            int pageSize = Convert.ToInt32(Request.Params["rows"] == null ? "10" : Request.Params["rows"]);
            string sort = " order by " + (Request.Params["sort"] == null ? "id" : Request.Params["sort"]) + " " + (Request.Params["order"] == null ? " desc " : Request.Params["order"]);
            string condition = " 1=1 and u.id<>21 ";
            string uid = txtUID.Text;// Request.Params["txtUID"] == null ? "" : Request.Params["txtUID"];
            string username = txtUserName.Text;// Request.Params["UserName"] == null ? "" : Request.Params["UserName"];
            if (uid.Trim() != "")
            {
                condition += " and uid like '%" + uid.Trim() + "%' ";
            }
            if (username.Trim() != "")
            {
                condition += " and username like '%" + username.Trim() + "%' ";
            }
            DataSet ds = access.GetAllUser(sort, pageSize, PageNumber, condition);
            string re = ToJson.DataTableToJson(ds.Tables[0].Rows[0][0].ToString(), "rows", ds.Tables[1]);
            Response.Write(re);
            Response.End();
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}